import {StackNavigationOptions} from "@react-navigation/stack";
import type {ApplicationStackParamList} from "@/types/navigation";
import Tabbar from "@/components/tabbar/Tabbar";
import * as Public from "@/screens/public";
import {Screen} from "@/types/public";

interface Route {
    name: keyof ApplicationStackParamList;
    component: Screen
    options?: StackNavigationOptions;
}

interface RouteGroup {
    screenOptions: StackNavigationOptions;
    children: Route[];
}

function forModules<M extends object>(modules: M): Route[] {
    let maps = Object.entries(modules) as [keyof ApplicationStackParamList, Screen][];
    return maps.map(([k, cmp]) => {
        return {
            name: k,
            component: cmp,
        }
    });
}

const routes: RouteGroup[] = [
    {
        screenOptions: {
            headerShown: false
        },
        children: [
            {
                name: "Tabbar",
                component: Tabbar,
            },

        ]
    },
    {
        screenOptions: {
            headerShown: false
        },
        children: [
            ...forModules(Public),

        ]
    }
]

export default routes;